<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 6、获取第38次斐波那契数列的值，以及 前38次值的总和;    (数列规律是：0   1   1   2   3   5   8   13  .....           分析规律是：第三个数=第一个数+第二个数)

        //  0  1   1   2    3

        //  +=  sum+=1   sum = sum+1；
        //  sum = sum + num;   sum += num;

        var a = 0;   //  第一个数
        var b = 1;   //  第二个数
        var c = 0;
        var sum = a + b;

        for(var i=2;i<35;i++) {
            c = a + b;
            a = b;
            b = c;
            sum += c;
        }
        console.log('第38个数为:'+c);
        console.log('前38次和为:' + sum);

        var num1 = 0;
        var num2 = 1;
        var num3 = 0;
        var times = 3;

        function count(t,n1,n2) {
            num3 = n1 + n2;
            n1 = n2;
            n2 = num3;
            t++;
            if(t == 36) {
                return num3;
            }else{
                return count(t,n1,n2)
            }
        }

        var num35 = count(times,num1,num2);
        console.log(num35);   //  5702887
    </script>
</body>
</html>